        var pickStore = new Ext.data.JsonStore({
			url: '/weihe/getDTCargo_depotList',
			root: 'datas',
			fields : [{
			        	   name:'pickId',mapping:'id'
			          },{
			        	   name:'pickAmount',mapping:'amount' 
			          },{
        				   name:'pickPrice',mapping:'price'
        			  },{
        				   name:'pickSum',mapping:'sum'
        			  },{
        				   name:'cargoId',mapping:'cargo', convert:function(v){ 
														return v ? v.id : undefined;}
        			  },{
        				   name:'pickLocation',mapping:'cargo', convert:function(v){ 
														return v ? v.location : undefined;}
        			  },{
        				  	name:'pickPlace',mapping:'cargo', convert:function(v){ 
															return v ? v.place : undefined;}
        			  },{
						   name:'pickCode',mapping:'cargo', convert:function(v){ 
														return v ? v.code : undefined;}
			          },{
			        	   name:'pickName',mapping:'cargo', convert:function(v){ 
														return v ? v.name : undefined;}
			          },{
			        	   name:'pickSpecs',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.specs : undefined;}
			          },{
			        	   name:'pickUnit',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.unit : undefined;}
			          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        var pickListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_depotList',
			root: 'datas',
			fields : [{
			        	   name:'pickListId',mapping:'id'
			          },{
			        	   name:'pickOrderNum',mapping:'orderNum' 
			          },{
        				   name:'pickListNum',mapping:'listNum'
        			  },{
        				   name:'pickDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'pickDepartment',mapping:'department'
        			  },{
        				   name:'pickType',mapping:'type'
        			  },{
        				   name:'pickRemark',mapping:'remark'
        			  },{
        				   name:'pickWarehouse',mapping:'warehouse'
        			  },{
        				   name:'pickMaker',mapping:'maker'
        			  },{
        				   name:'pickAuditor',mapping:'auditor'
        			  },{
        				   name:'pickFlag',mapping:'flag'
        			  }],
        	baseParams : {'tab': '领料'},
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
    	
    	
    
    	

picks = function(){
  return{
	  
	  listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height : 230,
			                    items  : [picks.listGrid(),picks.listForm()] 
		                      });
	  
	  return listPanel;
  	},

  	  listForm : function(){
	  
		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					Ext.getCmp("picksForm").buttons[0].enable();
					Ext.getCmp("picksForm").buttons[1].enable();
					Ext.getCmp("picksForm").buttons[2].enable();
					var tmp = listForm.form.findField('depotList.warehouse').getValue();
					Ext.getCmp('pickCode').getStore().setBaseParam('location',tmp);
					Ext.getCmp('pickCode').getStore().load({params : {query : '%'}});
					Ext.getCmp('pickName').getStore().setBaseParam('location',tmp);
					Ext.getCmp('pickName').getStore().load({params : {query : '%'}});
					if (listForm.form.findField("pickListId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_depotList',
						     success : function(form, action) {
							      if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
									    listForm.form.reset();
									    Ext.getCmp("picksForm").form.findField('depotList.id').setValue(action.result.depotList_id);
									    Ext.getCmp("pickGrid").getStore().removeAll();
									    Ext.getCmp("pickListGrid").getStore().load({params : {start : action.result.total-1, limit : 6}});;
								        })
							       }
						     },
							 failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
					      })
					}else {
							listForm.form.submit({
								url : '/weihe/update_depotList',
								success : function(form, action) {
									if (action.result.deny) {
									   Ext.Msg.alert('错误', action.result.msg);
								    }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("pickListGrid").getStore().reload();
										})
									}
							   },
								 failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
							})
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			Ext.getCmp("picksForm").form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("picksForm").buttons[0].disable();
		Ext.getCmp("picksForm").buttons[1].disable();
		Ext.getCmp("picksForm").buttons[2].disable();
		Ext.getCmp("pickGrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('pickListId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_depotList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							  if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										listForm.form.reset();
										listForm.buttons[0].setText('添加');
							 }else{
								Ext.Msg.alert('消息', json.msg, function() {
									Ext.getCmp("pickListGrid").getStore().load({params : {start : 0, limit : 6}});
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
								});
							 }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'depotList.id' : listForm.form.findField('pickListId').getValue() }
				});
			}
		}
	});
	
	  
	  var whComboData = new Ext.data.SimpleStore({
			fields : ['value','text'],
			data : [['A','A'],['B','B'],['C','C']]
		});
	  
			var listForm = new Ext.form.FormPanel({
			id : 'pickListForm',
			title : '产品领料信息',
			frame : true,
			region : 'east',
			width : 300,
			autoScroll : true,
			collapseMode :'mini',
			collapsible : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'pickListId',
				xtype : 'hidden',
				name : 'depotList.id'
			},{
				id: 'pickListNum',
				xtype : 'hidden',
				name : 'depotList.listNum'
			},{
				id: 'pickFlag',
				xtype : 'hidden',
				name : 'depotList.flag',
				value : '领料'
			},{
				id: 'pickOrderNum',
				fieldLabel: "订单号",
        	    name: "depotList.orderNum"
			},{
				id: 'pickDate',
              xtype: 'datefield',
              fieldLabel: "领料日期",
              format : 'Y-m-d',
  			allowBlank:false,
              name: "depotList.date"
			},{
				id: 'pickType',
				 fieldLabel: "领料类别",
               name: "depotList.type"
			},{
				id:'pickWarehouse',
				fieldLabel : '仓库',
				hiddenName : 'depotList.warehouse',
				xtype : 'combo',
				store : whComboData,
				emptyText : '请选择',
				mode : 'local',
				triggerAction : 'all',
				allowBlank:false,
				editable: false,
				valueField : 'value',
				displayField : 'text'
			},{
				id: 'pickDepartment',
				 fieldLabel: "部门",
             name: "depotList.department"
			},{
				id: 'pickRemark',
				 fieldLabel: "备注",
              name: "depotList.remark"
			},{
				id: 'pickMaker',
				 fieldLabel: "制单人",
             name: "depotList.maker"
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  

infoWin : function(){
  	  var infoWin = new Ext.Window({
  	  	id: 'pickInfo',
        title:'领料单查询',
        layout: 'fit',
        width:330,    
        height:250,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[picks.queryForm()] 
    });  
  		return infoWin;
  	},
  	
  	queryForm : function(){
  		

  	 var queryForm = new Ext.form.FormPanel({
			baseCls:"x-plain",
			frame : true,
			autoHeight : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
					  fieldLabel: "订单号",
      	    		  name: "depotList.orderNum"
			 	  },{
					  fieldLabel: "领料单号",
      	    		  name: "depotList.listNum"
			 	  },{
					  fieldLabel: "部门",
      	    		  name : 'depotList.department'
			 	  },{
					  fieldLabel: "领料类别",
      	    		  name : 'depotList.type'
			 	  },{
            		  xtype: 'datefield',
                      fieldLabel: "开始日期",
                      format : 'Y-m-d',
            		  name: "depotList.date"
				   },{
            		  xtype: 'datefield',
                      fieldLabel: "结束日期",
                      format : 'Y-m-d',
            		  name: "depotList.endDate"
				   }],
			buttons:[{
        		 text:'确认',
             	 handler:function(){
             	 	var orderNum = queryForm.form.findField('depotList.orderNum').getValue();
             	 	var listNum = queryForm.form.findField('depotList.listNum').getValue();
             	 	var department = queryForm.form.findField('depotList.department').getValue();
             	 	var type = queryForm.form.findField('depotList.type').getValue();
             	 	var date = queryForm.form.findField('depotList.date').getValue();
             	 	var endDate = queryForm.form.findField('depotList.endDate').getValue();
				 Ext.getCmp("pickListGrid").getStore().baseParams = {'flag': true,'tab':'领料','depotList.orderNum':orderNum,
					 													  'depotList.listNum':listNum,
					 													  'depotList.type':type,
					 													  'depotList.department':department,
					 													  'depotList.date':date,
					 													  'depotList.endDate':endDate};
				 Ext.getCmp("pickListGrid").getStore().load({params : {start : 0, limit : 6}});
				 queryForm.form.reset();
                 Ext.getCmp("pickInfo").close();
              	
              	}
              },{
                 text:'取消',
                 handler:function(){
                 	queryForm.form.reset();
                 	Ext.getCmp("pickInfo").close();
                 }
              }]   
        });
        return queryForm;
  	
  	},
	  
	  
	  
listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : pickListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'pickListGrid',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   tbar:[{
	   						text:"输入查询条件",
								handler:function(){
										picks.infoWin().show();
								}
	   					},"-",{
	   						text:"查看全部",
								handler:function(){
									Ext.getCmp("pickListGrid").getStore().baseParams = {'flag': false,'tab':'领料'};
									Ext.getCmp("pickListGrid").getStore().load({params : {start : 0, limit : 6}});
								}
	   			},"-"],
		   store : pickListStore,
		   columns: [
		             {header : '订单号', dataIndex : 'pickOrderNum'},
		             {header : '领料单号', dataIndex : 'pickListNum'},
		             {header : '领料日期', dataIndex : 'pickDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '领料类别', dataIndex : 'pickType', menuDisabled : true},
		             {header : '部门', dataIndex : 'pickDepartment', menuDisabled : true},
		             {header : '仓库', dataIndex : 'pickWarehouse', menuDisabled : true},
		             {header : '备注', dataIndex : 'pickRemark', menuDisabled : true},
		             {header : '制单人', dataIndex : 'pickMaker', menuDisabled : true},
		             {header : '审核人', dataIndex : 'pickAuditor', menuDisabled : true}
		             ],
       sm : rowSelectionModel,
       listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		Ext.getCmp("pickListForm").form.loadRecord(record);
			   		Ext.getCmp("picksForm").form.findField('depotList.id').setValue(record.id);
			   		Ext.getCmp("picksForm").buttons[0].enable();
					Ext.getCmp("picksForm").buttons[1].enable();
					Ext.getCmp("picksForm").buttons[2].enable();
					Ext.getCmp("pickListForm").buttons[0].setText('修改');
					Ext.getCmp('pickCode').getStore().setBaseParam('location',record.get('pickWarehouse'));
					Ext.getCmp('pickCode').getStore().load({params : {query : '%'}});
					Ext.getCmp('pickName').getStore().setBaseParam('location',record.get('pickWarehouse'));
					Ext.getCmp('pickName').getStore().load({params : {query : '%'}});
					Ext.getCmp("pickGrid").getStore().baseParams = {'depotList.id': record.id};
					Ext.getCmp("pickGrid").getStore().load({params : {start : 0, limit : 6}});
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
	  
	  
	  
	  
	  
	  
	  
	  
	  
	
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : pickStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'pickGrid',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : pickStore,
		   columns: [
		             {header : '产品编号', dataIndex : 'pickCode'},
		             {header : '产品名称', dataIndex : 'pickName'},
		             {header : '规格型号', dataIndex : 'pickSpecs'},
		             {header : '单位', dataIndex : 'pickUnit'},
		             {header : '所在仓库', dataIndex : 'pickLocation'},
		             {header : '存放位置', dataIndex : 'pickPlace'},
		             {header : '单价', dataIndex : 'pickPrice'},
		             {header : '数量', dataIndex : 'pickAmount'},
		             {header : '金额', dataIndex : 'pickSum'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("picksForm").form.loadRecord(record);
			   Ext.getCmp("picksForm").buttons[0].setText('修改');
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	picksForm : function(){
		
		var codestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByCode_depotList',
			root: 'codes',
			totalProperty: 'count',
			fields: ['code']
		});
		
		var namestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByname_depotList',
			root: 'names',
			totalProperty: 'count',
			fields: ['name']
		});
		
		var codeCombo = {
				id : 'pickCode',
				xtype: 'combo',
				fieldLabel: '产品编号',
				store: codestore,
				typeAhead: false,
				name : 'cargo.code',
				loadingText: '查找中...',
				emptyText: '请输入3位以上编号', 
				minChars: 3,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'code',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getCode_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									  picksForm.form.findField('pickName').setValue(json.name);
									  picksForm.form.findField('pickSpecs').setValue(json.specs);
									  picksForm.form.findField('pickUnit').setValue(json.unit);
									  picksForm.form.findField('pickPrice').setValue(json.price);
									  picksForm.form.findField('pickPlace').setValue(json.place);
									  picksForm.form.findField('cargo.id').setValue(json.id);
									},
								params : 'query=' + record.get('code')
							});
				    }
				}
		}
		var nameCombo = {
				id : 'pickName',
				xtype: 'combo',
				fieldLabel: '产品名称',
				store: namestore,
				typeAhead: false,
				name : 'cargo.name',
				loadingText: '查找中...',
				emptyText: '请输入产品名称', 
				minChars: 2,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'name',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getName_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									  picksForm.form.findField('pickCode').setValue(json.code);
									  picksForm.form.findField('pickSpecs').setValue(json.specs);
									  picksForm.form.findField('pickUnit').setValue(json.unit);
									  picksForm.form.findField('pickPrice').setValue(json.price);
									  picksForm.form.findField('pickPlace').setValue(json.place);
									  picksForm.form.findField('cargo.id').setValue(json.id);
									},
								params : 'query=' + record.get('name')
							});
				    }
				}
		}

		var button_add = new Ext.Button({
			text : '添加',
			disabled : true,
			handler : function() {

					progressConsole();
				if(picksForm.form.isValid()){ 	
					if (picksForm.form.findField("dt_Cargo.id").getValue() == "") {
						picksForm.form.submit({
						  url : '/weihe/addDTCargo_depotList',
						   success : function(form, action) {
							 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									 var i = picksForm.form.findField('depotList.id').getValue();
									   picksForm.form.reset();
									   picksForm.form.findField('depotList.id').setValue(i);
									   Ext.getCmp("pickGrid").getStore().baseParams = {'depotList.id': i};
									   Ext.getCmp("pickGrid").getStore().load({params : {start : 0, limit : 6}});
									
								})
							  }
						    },
							 failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    })
					}else {
						picksForm.form.submit({
							  url : '/weihe/updateDTCargo_depotList',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = picksForm.form.findField('depotList.id').getValue();
										picksForm.form.reset();
										 picksForm.form.findField('depotList.id').setValue(i);
										Ext.getCmp("pickGrid").getStore().reload();
										    picksForm.buttons[0].setText('添加');
										
									})
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = picksForm.form.findField('depotList.id').getValue();
			picksForm.form.reset();
			picksForm.form.findField('depotList.id').setValue(i);
			picksForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = picksForm.form.findField('dt_Cargo.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteDTCargo_depotList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
						  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("pickGrid").getStore().load({params : {start : 0, limit : 6}});
								var i = picksForm.form.findField('depotList.id').getValue();
								picksForm.form.reset();
								picksForm.form.findField('depotList.id').setValue(i);
								picksForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'dt_Cargo.id': id , 'depotList.id' : picksForm.form.findField('depotList.id').getValue() }
				});
			}
		}
	});
	

	
		var picksForm = new Ext.form.FormPanel({
			id : 'picksForm',
			title : '货物信息',
			frame : true,
			width : 300,
			region : 'east',
			autoScroll : true,
			collapseMode :'mini',
			collapsible : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{  // Ext.form.Hidden
				id: 'pickId',
				xtype : 'hidden',  // 隐藏的表单
				name : 'dt_Cargo.id'
			},{  // Ext.form.Hidden
				xtype : 'hidden',  // 隐藏的表单
				name : 'depotList.id'
			},{  // Ext.form.Hidden
				xtype : 'hidden',  // 隐藏的表单
				name : 'cargo.id'
			},codeCombo ,nameCombo
			 ,{
				id:'pickSpecs',
				fieldLabel : '规格型号',
				name : 'cargo.specs',
				readOnly: true
			},{
				id:'pickUnit',
				fieldLabel : '单位',
				name : 'cargo.unit',
				readOnly: true
			},{
				id:'pickPlace',
				fieldLabel : '存放位置',
 				name : 'cargo.place',
 				readOnly: true
			},{
				id:'pickPrice',
				fieldLabel : '单价',
				name : 'dt_Cargo.price',
				readOnly: true
			},{
				id:'pickAmount',
				fieldLabel : '数量',
				name : 'dt_Cargo.amount',
				allowBlank:false,
				blankText:'请输入数量',
				regex : /^[1-9]\d*$/,
			    regexText:'请输入有效的数量'  
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return picksForm;
	}
  }
}();








